$.namespace('act.taskProcessList');

act.taskProcessList = function() {

	return {
		init : function() {
			this.initGrid();
			this.initComponents();
		},
		initComponents : function(){
			
		},
		initGrid : function() {
			$('#grid').datagrid({
				method : 'GET',
				url : ctxRest + '/act/task/list-process',
				contentType : 'application/json;charset=utf-8',
				fit : true,
				fitColumns : true,
				rownumbers : true,
				nowrap : true,
				striped : true,
				remoteSort : false,
				singleSelect : true,
				border : false,
				idField : 'id',
				columns : [ [ {
					title : '流程分类',
					field : 'process.category',
					width : 60,
					formatter : function(value, row, index){
						return row.process.category;
					}
				}, {
					title : '流程标识',
					field : 'process.key',
					width : 80,
					formatter : function(value, row, index){
						return row.process.key;
					}
				}, {
					title : '流程名称',
					field : 'process.name',
					width : 100,
					formatter : function(value, row, index){
						return row.process.name;
					}
				}, {
					title : '流程图',
					field : 'diagramResourceName',
					width : 100,
					formatter : function(value, row, index){
						return '<a href="' + ctxRest + '/act/process/resource/read?procDefId=' + row.process.id + '&resType=image" target="_blank">' + row.process.diagramResourceName + '</a>';;
					}
				}, {
					title : '流程版本',
					field : 'version',
					width : 80,
					formatter : function(value, row, index){
						return row.process.version;
					}
				}, {
					title : '更新时间',
					field : 'deploymentTime',
					width : 100,
					formatter : function(value, row, index){
						return row.deployment.deploymentTime;
					}
				}, {
					title : '操作',
					field : 'option',
					width : 120,
					formatter : function(value, row, index){
						var opts = '';
						opts += '<a href="javascript:void(0);" onClick="act.taskProcessList.startProcess(' + "'" + row.process.id + "'" + ')">[ 启动流程 ]</a>';
						return opts;
					}
				} ] ]
				//toolbar : '#toolbar'
			});
		},
		startProcess : function(procDefId) {
			if (procDefId) {
				$.ajax({
					type : 'POST',
					url : ctxRest + '/act/task/form',
					contentType : 'application/json;charset=utf-8',
					data : JSON.stringify({
						procDefId : procDefId
					}),
					beforeSend:function(){
						progressLoad();
					},
					success : function(result){
						if (result && result.url) {
							//console.log(ctx + result.url);return;
							window.location.href = (ctx + result.url);
						}
					}
				});
			}
		}
		
	};
}();

$(function() {
	act.taskProcessList.init();
})